package com.example.juc.stream;

import java.util.Arrays;
import java.util.List;

public class Test {
    public static void main(String[] args) {
        User u1 = new User(1,"a",21);
        User u2 = new User(2,"b",22);
        User u3 = new User(3,"c",23);
        User u4 = new User(4,"d",24);
        User u5 = new User(5,"e",25);

        List<User> list = Arrays.asList(u1,u2,u3,u4,u5);

        list.stream().filter((x)->{
            return x.getId()%2 ==0;
        }).forEach(System.out::println);

        System.out.println("------------");
        list.stream().filter((x)->{
            return x.getAge()>23;
        }).forEach(System.out::println);
        System.out.println("------------");

        list.stream()
                .map(x->x.getName().toUpperCase())
                .forEach(System.out::println);
        System.out.println("------------");

        list.stream()
                .map(User::getName)
                .sorted((x,y)->{return y.compareTo(x);});

        System.out.println("---------------");

        list.stream().limit(2).forEach(System.out::println);

    }
}
